import request from '@/utils/request'

// 获取商品列表
export function getGoodsList(query) {
  return request({
    url: '/goods/projectGoods/paging',
    method: 'get',
    params: query
  })
}

// 已选未选商品分页
export function pageSelectGoods(query) {
  return request({
    url: '/goods/projectGoods/pageSelectGoods',
    method: 'get',
    params: query
  })
}

// 商品组已选未选商品分页
export function pageGroupSelectGoods(query) {
  return request({
    url: '/goods/projectGoods/pageGroupSelectGoods',
    method: 'get',
    params: query
  })
}

// 仓库选择商品分页
export function pageWarehouseSelectGoods(query) {
  return request({
    url: '/goods/projectGoods/pageWarehouseSelectGoods',
    method: 'get',
    params: query
  })
}

/**
 * 获取企业商品类目
 * @param enterpriseId
 */
export function listGoodsCategory(enterpriseId) {
  if (!enterpriseId) {
    return
  }
  return request({
    url: '/goods/projectGoods/listGoodsCategory',
    method: 'get',
    params: {
      enterpriseId: enterpriseId
    }
  })
}

/**
 * 获取企业批发商品类目别名
 * @param enterpriseId
 */
export function listWholesaleGoodsCategory(enterpriseId) {
  return request({
    url: '/goods/projectGoods/listWholesaleGoodsCategory',
    method: 'get',
    params: {
      enterpriseId: enterpriseId
    }
  })
}

// 企业关联平台分类
export function saveEnterpriseThirdCategory(enterpriseCategoryId, categoryId, platformType) {
  return request({
    url: '/goods/enterpriseGoodsCategory/saveEnterpriseThirdCategory',
    method: 'post',
    params: {
      enterpriseCategoryId: enterpriseCategoryId,
      categoryId: categoryId,
      platformType: platformType
    }
  })
}

// 上架商品
export function upGoods(goodsId, goodsType) {
  if (!goodsId) {
    return false
  }
  return request({
    url: '/goods/projectGoods/upGoods',
    method: 'post',
    params: {
      goodsId: goodsId,
      goodsType: goodsType
    }
  })
}

// 下架商品
export function downGoods(goodsId, goodsType) {
  if (!goodsId) {
    return false
  }
  return request({
    url: '/goods/projectGoods/downGoods',
    method: 'post',
    params: {
      goodsId: goodsId,
      goodsType: goodsType
    }
  })
}

// 删除任务
export function deleteGoods(goodsId, goodsType) {
  return request({
    url: '/goods/projectGoods/delete',
    method: 'post',
    params: {
      goodsId: goodsId,
      goodsType: goodsType
    }
  })
}

// 批量下架
export function handleBatchDown(data) {
  return request({
    url: '/goods/projectGoods/batchDown',
    method: 'post',
    data: data
  })
}

// 批量删除
export function handleDelete(data) {
  return request({
    url: '/goods/projectGoods/batchDelete',
    method: 'post',
    data: data
  })
}

// 批量更改商品选品库状态
export function batchSelectionGoods(data) {
  return request({
    url: '/goods/projectGoods/batchSelectionGoods',
    method: 'post',
    data: data
  })
}

// 批量复制
export function batchCopy(data) {
  return request({
    url: '/goods/projectGoods/batchCopy',
    method: 'post',
    data: data
  })
}

// 批量设置分类
export function handleBatchCategory(data) {
  return request({
    url: '/goods/projectGoods/batchGoodsCategory',
    method: 'post',
    data: data
  })
}

// 批量设置预警库存
export function handleBatchStockWarn(params) {
  return request({
    url: '/goods/projectGoods/batchUpdateStockWarn',
    method: 'post',
    params
  })
}

// 批量设置分销提成
export function handleBatchSetDistribute(data) {
  return request({
    url: '/goods/projectGoods/batchSetDistribute',
    method: 'post',
    data: data
  })
}

// 保存
export function saveGoods(data) {
  return request({
    url: '/goods/projectGoods/save',
    method: 'post',
    data: data
  })
}

// 查询商品详情
export function getGoodsDetail(data) {
  return request({
    url: '/goods/projectGoods/getGoodsDetail',
    method: 'post',
    params: data
  })
}

// 获取分类SKU 集合
export function listCategorySku(categoryId) {
  return request({
    url: '/goods/projectGoods/listCategorySku',
    method: 'get',
    params: {
      categoryId
    }
  })
}

// 获取权限菜单节点
export function getCategoryTree(query) {
  return request({
    url: '/system/projectGoodsCategory/getCategoryTree',
    method: 'get',
    params: query
  })
}
// 分页加载分销申请
export function pagingProjectGoodsApply(data) {
  return request({
    url: '/goods/projectGoods/pagingProjectGoodsApply',
    method: 'get',
    params: data
  })
}
// 更新微客申请分销状态
export function updateProjectGoodsApplyStatus(data) {
  return request({
    url: '/goods/projectGoods/updateProjectGoodsApplyStatus',
    method: 'get',
    params: data
  })
}
// 修改备注
export function changeApplyRemark(data) {
  return request({
    url: '/goods/projectGoods/changeApplyRemark',
    method: 'get',
    params: data
  })
}
// 商品设置
export function getShopSetting(data) {
  return request({
    url: '/goods/projectGoods/getShopSetting',
    method: 'get',
    params: data
  })
}
// 保存店铺设置
export function saveShopSetting(data) {
  return request({
    url: '/goods/projectGoods/saveShopSetting',
    method: 'post',
    data: data
  })
}
// 批量同意
export function handleBatchAgreeRefuse(data) {
  return request({
    url: '/goods/projectGoods/handleBatchAgreeRefuse',
    method: 'post',
    data: data
  })
}
// 获取卡片申请数量
export function countGoodsApply(data) {
  return request({
    url: '/goods/projectGoods/countGoodsApply',
    method: 'get',
    params: data
  })
}

// 获取运费模版集合
export function listGoodsTemplate(data) {
  return request({
    url: '/goods/projectGoods/listGoodsTemplate',
    method: 'get',
    params: data
  })
}

// 商品分页（sku级）商品选择组件使用
export function pagingGoodsSku(params) {
  return request({
    url: '/goods/projectGoods/pagingGoodsSku',
    method: 'get',
    params: params
  })
}

// 检查导入淘宝商品是否已完成
export function checkUploadTaoBaoZip(id) {
  return request({
    url: '/goods/supplierGoods/checkUploadTaoBaoZip',
    method: 'get',
    params: {
      id
    }
  })
}

// 批量设置运费模板
export function batchSetDeliveryTemplate(data) {
  return request({
    url: '/goods/projectGoods/batchSetDeliveryTemplate',
    method: 'post',
    data: data
  })
}

/**
 * 根据商品ID更新商品价格
 * @param {Object} params
 */
export function updateGoodsSellPrice(params) {
  return request({
    url: '/goods/projectGoods/updateGoodsSellPrice',
    method: 'get',
    params: params
  })
}
/**
 * 根据商品ID更新商品库存
 * @param {Object} params
 */
export function updateGoodsStock(params) {
  return request({
    url: '/goods/projectGoods/updateGoodsStock',
    method: 'get',
    params: params
  })
}
/**
 * 根据商品ID更新商品序号
 * @param {Object} params
 */
export function updateGoodsSortNo(params) {
  return request({
    url: '/goods/projectGoods/updateGoodsSortNo',
    method: 'get',
    params: params
  })
}
// 商品定时上下架修改
export function timingUpOrDownGoods(goodsId, timeUploadOrDown, openingTime, isGoodsTiming) {
  return request({
    url: '/goods/projectGoods/timingUpOrDownGoods',
    method: 'post',
    params: {
      goodsId: goodsId,
      timeUploadOrDown: timeUploadOrDown,
      openingTime: openingTime,
      isGoodsTiming: isGoodsTiming
    }
  })
}
// 商品限购修改
export function updateGoodsLimit(goodsId, limitType, personLimitType, singleLimitNum, isGoodsLimit) {
  return request({
    url: '/goods/projectGoods/updateGoodsLimit',
    method: 'post',
    params: {
      goodsId: goodsId,
      limitType: limitType,
      personLimitType: personLimitType,
      singleLimitNum: singleLimitNum,
      isGoodsLimit: isGoodsLimit
    }
  })
}

// 导入商品
export function importGoods(data) {
  return request({
    url: '/goods/projectGoods/doImportProjectGoods',
    method: 'post',
    data: data
  })
}

/**
 * 供货联盟商品操作； operationType：1-加入，2-移出，3-上架，4-下架
 */
export function operationSupplyAllianceGoods(goodsIds, operationType) {
  return request({
    url: '/goods/projectGoods/operationSupplyAllianceGoods',
    method: 'get',
    params: {
      goodsIds: goodsIds,
      operationType: operationType
    }
  })
}

// 获取公共选择商品列表
export function getCommonSelectGoodsList(query) {
  return request({
    url: '/goods/projectGoods/pagingCommonSelectGoodsPage',
    method: 'get',
    params: query
  })
}
// 保存批量修改跨境商品
export function saveImportGoodsForBatchSetCustomsGoodsCode(data) {
  var url = '/goods/projectGoods/saveImportGoodsForBatchSetCustomsGoodsCode'
  if (data.supplierId && data.supplierId !== 0) {
    url = '/goods/supplierGoods/saveImportGoodsForBatchSetCustomsGoodsCode'
  }
  return request({
    url: url,
    method: 'get',
    params: data
  })
}

// 获取选择商品列表，用于计划选商品
export function pagingSelectGoodsByPlan(query) {
  return request({
    url: '/goods/projectGoods/pagingSelectGoodsByPlan',
    method: 'get',
    params: query
  })
}

// 获取选择商品id列表，用于计划选商品
export function getSelectGoodsIdsByPlan(query) {
  return request({
    url: '/goods/projectGoods/getSelectGoodsIdsByPlan',
    method: 'get',
    params: query
  })
}

